<?php

abstract class ZFBootstrap_Controller extends ZFKiller_Controller {

	public function init () {
		parent::init();

		$this->view->addHelperPath(PATH_ZFEXTEND . '/ZFBootstrap/View/Helper/', 'ZFBootstrap_View_Helper');

		$this->initNavigation();
		$this->initDoctype();
		$this->initTitle();
		$this->initDefaultCss();
		$this->initDefaultJs();
	}

	protected function initDefaultCss () {
		$this->view->headLink()->appendStylesheet(ZFBOOTSTRAP_LIB_DIR_CSS . '/bootstrap.min.css');
		$this->view->headLink()->appendStylesheet(ZFBOOTSTRAP_LIB_DIR_CSS . '/bootstrap-responsive.min.css');
		$this->view->headLink()->appendStylesheet(HREF_STATIC_CSS . '/bootstrap-customize.css');
	}

	protected function initDefaultJs () {
		$this->view->headScript()->appendFile(HREF_STATIC_LIB . '/jq.js');
		$this->view->headScript()->appendFile(ZFBOOTSTRAP_LIB_DIR_JS . '/bootstrap.min.js');
	}

	protected function initDoctype () {
		$this->view->getHelper('doctype')->setDoctype(Zend_View_Helper_Doctype::HTML5);
	}

	protected function initNavigation ($options = null) {

	}

	protected function initTitle () {
		$this->view->headTitle('Painel de controle ' . SITE_TITLE)
				->setSeparator(' » ')
				->setDefaultAttachOrder(Zend_View_Helper_Placeholder_Container_Abstract::PREPEND)
		;
	}

	protected function markActiveNav ($search, $type = 'id') {
		$container = $this->view->navigation()->getContainer();

		if (is_array($search)) {
			$activeNav = $container;

			foreach ($search as $item) {
				$activeNav = $activeNav->findOneBy($item[1], $item[0]);
				if ($activeNav === null) {
					break;
				}
			}
		} else {
			$activeNav = $container->findOneBy($type, $search);
		}
		if (null !== $activeNav) {
			$activeNav->active = true;
			$activeNav->setClass('active');
		}
	}

}